package com.zlf.demo.demo;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @ClassName Test1
 * @Description TODO
 * @Author 张龙飞
 * @Date 2021/3/10 16:56
 */
public class Test1 {

    public static void main(String[] args) throws ParseException, InterruptedException {

        Date date = new Date();
        System.out.println(date);
        /**
         *  模拟SimpleDateFormat 的线程安全问题
         *
         *  Exception in thread "Thread-30" java.lang.NumberFormatException: multiple points
         *
         *  Exception in thread "Thread-24" java.lang.NumberFormatException: For input string: "E.250214E4"
         *
         */
        SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-dd");

        for (int i = 0; i < 100; i++) {
            new Thread(() -> {
                for (int j = 0; j < 20; j++) {
                    try {
                        String format = sdf.format(date);
                        Date d = sdf.parse(format);
                        System.out.println(d);
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                }
            }).start();
        }
    }

}
